/*
 * LowerPanel.java
 * 
 * Created by demory on Mar 5, 2009, 10:28:21 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.rtemaster.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import org.fpdev.apps.rtemaster.RouteMaster;

/**
 *
 * @author demory
 */
public class LowerPanel extends JPanel {


  private RouteMaster av_;

  private JPanel leftPanel_,  tablePanel_;
  private JSplitPane splitPane_;

  // keep track of the last visible height for when panel is maximized after
  // having been minimized
  private int lastHeight_;


  public LowerPanel(RouteMaster av) {
    super(new BorderLayout());

    av_ = av;
    lastHeight_ = 235;

    addComponentListener(new ComponentAdapter() {

      @Override
      public void componentResized(ComponentEvent e) {
        System.out.println("det panel resized");
        lastHeight_ = getHeight();
        av_.getAnalysisOps().renderBikeElevGraph();
      }
    });
    leftPanel_ = new JPanel(new BorderLayout());
    tablePanel_ = new JPanel(new BorderLayout());
    splitPane_ = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane_.setOneTouchExpandable(true);
  }

  public void initPanel(boolean split) {
    removeAll();
    if (split) {
      splitPane_.add(leftPanel_, JSplitPane.LEFT);
      leftPanel_.setMinimumSize(new Dimension(200, 1));
      splitPane_.add(tablePanel_, JSplitPane.RIGHT);
      add(splitPane_, BorderLayout.CENTER);
    } else {
      add(tablePanel_, BorderLayout.CENTER);
      tablePanel_.add(new JLabel("foo"));
    }
  }



  public void setTable(JTable table) {
    clearTable();
    JScrollPane scrollPane = new JScrollPane(table);
    tablePanel_.add(scrollPane, BorderLayout.CENTER);
  }

  public void clearTable() {
    tablePanel_.removeAll();
  }

  public void repaintTable() {
    tablePanel_.revalidate();
  }

  public int getLastHeight() {
    return lastHeight_;
  }

  void captureLastHeight() {
    lastHeight_ = this.getHeight();
  }

  public void setLeftPanel(JPanel panel) {
    leftPanel_.removeAll();
    leftPanel_.add(panel, BorderLayout.CENTER);
    revalidate();
  }

  public void setDividerLocation(double div) {
    splitPane_.setDividerLocation(div);
  }

}
